package com.bytedance.scenedemo;

import com.bytedance.scene.group.UserVisibleHintGroupScene;
import com.bytedance.scene.ktx.SceneExtensions;
import com.bytedance.scenedemo.benchmark.BenchmarkSamples;
import com.bytedance.scenedemo.benchmark.performance.PerformanceDemo;
import com.bytedance.scenedemo.extreme_case.Case0Scene;
import com.bytedance.scenedemo.extreme_case.Case1Scene;
import com.bytedance.scenedemo.extreme_case.Case2Scene;
import com.bytedance.scenedemo.extreme_case.Case3Scene;
import com.bytedance.scenedemo.extreme_case.Case4Scene;
import com.bytedance.scenedemo.extreme_case.Case5Scene;
import com.bytedance.scenedemo.extreme_case.EmptyScene;
import com.bytedance.scenedemo.restore.SupportRestoreAbility;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.Operation;
import ohos.agp.components.Button;
import ohos.agp.components.Component;
import ohos.agp.components.ComponentContainer;
import ohos.agp.components.LayoutScatter;
import ohos.agp.components.Text;

/**
 * Created by JiangQi on 8/21/18.
 */
public class CaseListDemo extends UserVisibleHintGroupScene implements Component.ClickedListener{
    @Override
    public ComponentContainer onCreateView(LayoutScatter layoutScatter, ComponentContainer container, Intent savedInstanceState) {
        Component layout=layoutScatter.parse(ResourceTable.Layout_fraction_caselist_demo,container,false);
        Text textHint= (Text) layout.findComponentById(ResourceTable.Id_text_case_sample_hint);
        textHint.setVisibility(Component.HIDE);
        textHint.setText(BenchmarkSamples.class.getName());
        Button btnDesRestore = (Button) layout.findComponentById(ResourceTable.Id_main_case_destroy_restore);
        btnDesRestore.setClickedListener(this);
        Button btnPushAndPop = (Button) layout.findComponentById(ResourceTable.Id_main_case_push_and_pop);
        btnPushAndPop.setClickedListener(this);
        Button btnPushAndMany = (Button) layout.findComponentById(ResourceTable.Id_main_case_push_many);
        btnPushAndMany.setClickedListener(this);
        Button btnPopAndMany = (Button) layout.findComponentById(ResourceTable.Id_main_case_pop_many);
        btnPopAndMany.setClickedListener(this);
        Button btnPopRemove = (Button) layout.findComponentById(ResourceTable.Id_main_case_push_pop_remove);
        btnPopRemove.setClickedListener(this);
        Button btnPushPopLifeCycle = (Button) layout.findComponentById(ResourceTable.Id_main_case_push_pop_in_lifecycle);
        btnPushPopLifeCycle.setClickedListener(this);
        Button btnAddRemoveScene = (Button) layout.findComponentById(ResourceTable.Id_main_case_add_remove_group_scene);
        btnAddRemoveScene.setClickedListener(this);
        Button btnPushPopFinish = (Button) layout.findComponentById(ResourceTable.Id_main_case_push_pop_after_finish);
        btnPushPopFinish.setClickedListener(this);
        return (ComponentContainer) layout;
    }

    @Override
    public void onClick(Component component) {
        switch (component.getId()){
            case ResourceTable.Id_main_case_destroy_restore:
                Intent intent = new Intent();
                Operation operation = new Intent.OperationBuilder()
                        .withDeviceId("")
                        .withBundleName(getAbility().getBundleName())
                        .withAbilityName(SupportRestoreAbility.class.getName())
                        .build();
                intent.setOperation(operation);
                SceneExtensions.requireNavigationScene(this).startAbility(intent);
                break;
            case ResourceTable.Id_main_case_push_and_pop:
                SceneExtensions.requireNavigationScene(this).push(Case0Scene.class);
                break;
            case ResourceTable.Id_main_case_push_many:
                SceneExtensions.requireNavigationScene(this).push(Case1Scene.class);
                break;
            case ResourceTable.Id_main_case_pop_many:
                SceneExtensions.requireNavigationScene(this).push(Case2Scene.class);
                break;
            case ResourceTable.Id_main_case_push_pop_remove:
                SceneExtensions.requireNavigationScene(this).push(Case3Scene.class);
                break;
            case ResourceTable.Id_main_case_push_pop_in_lifecycle:
                SceneExtensions.requireNavigationScene(this).push(Case4Scene.class);
                break;
            case ResourceTable.Id_main_case_add_remove_group_scene:
                SceneExtensions.requireNavigationScene(this).push(Case5Scene.class);
                break;
            case ResourceTable.Id_main_case_push_pop_after_finish:
                getSceneContext().terminateAbility();
                SceneExtensions.requireNavigationScene(this).push(EmptyScene.class);
                break;
            default:
        }
    }
}